import router from "./index";
import store from "@/store";

router.beforeEach((to,from,next) => {
    if(to.meta.isLogin){
        let token = store.state.login.user.token;
        if(token){
            if(to.path === "/notice" && store.state.login.user.position !== 1 && store.state.login.user.position !== 2){
                next({
                    name: "Index"
                });
            }else if(to.path === "/hostel" && store.state.login.user.position !== 1 && store.state.login.user.position !== 2 && store.state.login.user.position !== 0){
                next({
                    name: "Index"
                });
            }else if(to.path === "/payFees" && store.state.login.user.position !== 1 && store.state.login.user.position !== 2 && store.state.login.user.position !== 0){
                next({
                    name: "Index"
                });
            }else if(to.path === "/owner" && store.state.login.user.position !== 1 && store.state.login.user.position !== 2){
                next({
                    name: "Index"
                });
            }else if(to.path === "/maintenance" && store.state.login.user.position === 4){
                next({
                    name: "Index"
                });
            }else{
                next();
            }
            next();
        }else{
            next({
                name: "Login"
            })
        }
    }else{
        next()
    }
})